package com.youbug.mall.order_oms.service.impl;

import com.youbug.mall.order_oms.entity.OmsPaymentInfo;
import com.youbug.mall.order_oms.mapper.OmsPaymentInfoMapper;
import com.youbug.mall.order_oms.service.IOmsPaymentInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.youbug.mall.order_oms.entity.OmsPaymentInfo;
import org.springframework.util.ObjectUtils;
import com.youbug.common.vo.QueryVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.util.StringUtils;
import org.springframework.util.ObjectUtils;

/**
 * <p>
 * 支付信息表 服务实现类
 * </p>
 *
 * @author youbug
 * @since 2024-07-20
 */
@Service
public class OmsPaymentInfoServiceImpl extends ServiceImpl<OmsPaymentInfoMapper, OmsPaymentInfo> implements IOmsPaymentInfoService {

        @Override
        public IPage<OmsPaymentInfo> getOmsPaymentInfoPage(QueryVo<OmsPaymentInfo> queryVo) {

        Page<OmsPaymentInfo> paramPage = new Page<>();

        paramPage.setCurrent(queryVo.getCurrentPage());

        paramPage.setSize(queryVo.getPageSize());

        QueryWrapper<OmsPaymentInfo> wrapper = new QueryWrapper<>();

        OmsPaymentInfo omsPaymentInfo = queryVo.getPayload();

        if(!ObjectUtils.isEmpty(omsPaymentInfo)){
                    if(omsPaymentInfo.getId()!=null){
                    wrapper.eq("id", omsPaymentInfo.getId());
                    }
            if(StringUtils.hasText(omsPaymentInfo.getOrderSn())){
                wrapper.eq("order_sn", omsPaymentInfo.getOrderSn());
            }
                    if(omsPaymentInfo.getOrderId()!=null){
                    wrapper.eq("order_id", omsPaymentInfo.getOrderId());
                    }
            if(StringUtils.hasText(omsPaymentInfo.getAlipayTradeNo())){
                wrapper.eq("alipay_trade_no", omsPaymentInfo.getAlipayTradeNo());
            }
            if(StringUtils.hasText(omsPaymentInfo.getSubject())){
                wrapper.eq("subject", omsPaymentInfo.getSubject());
            }
            if(StringUtils.hasText(omsPaymentInfo.getPaymentStatus())){
                wrapper.eq("payment_status", omsPaymentInfo.getPaymentStatus());
            }
            if(!ObjectUtils.isEmpty(omsPaymentInfo.getConfirmTime())){
                wrapper.gt("confirm_time", omsPaymentInfo.getConfirmTime());
            }
            if(StringUtils.hasText(omsPaymentInfo.getCallbackContent())){
                wrapper.eq("callback_content", omsPaymentInfo.getCallbackContent());
            }
            if(!ObjectUtils.isEmpty(omsPaymentInfo.getCallbackTime())){
                wrapper.gt("callback_time", omsPaymentInfo.getCallbackTime());
            }
        }
        if(!ObjectUtils.isEmpty(queryVo.getStartTime())){
            wrapper.gt("create_time", queryVo.getStartTime());
        }
        if(!ObjectUtils.isEmpty(queryVo.getEndTime())){
            wrapper.lt("create_time", queryVo.getEndTime());
        }
        wrapper.orderByDesc("create_time");

        Page<OmsPaymentInfo> page = this.page(paramPage, wrapper);

        return page;
        }

       /* @Transactional(transactionManager = "transactionManagerXXX", rollbackFor = Exception.class)
        public boolean saveBatch(Collection<OmsPaymentInfo> entityList) {
        return saveBatch(entityList, DEFAULT_BATCH_SIZE);
        }
        */
}
